<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>视频集锦 - 体育比分网</title>
    <script src="../common/js/tailwindcss.js"></script>
    <script src="../common/js/lucide.min.js"></script>
    <!-- 添加 ScoreBat 小部件脚本 -->
    <script src="https://www.scorebat.com/embed/embed.js?v=arrv"></script>
    <style>
        /* 确保视频容器响应式 */
        .scorebat-video-container {
            width: 100%;
            margin-bottom: 20px;
        }

        /* 自定义加载动画 */
        .loading-spinner {
            border: 4px solid #f3f3f3;
            border-top: 4px solid #3498db;
            border-radius: 50%;
            width: 40px;
            height: 40px;
            animation: spin 1s linear infinite;
        }

        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }
    </style>
</head>
<body class="min-h-screen bg-gray-100">
<!-- 主导航栏 -->
<nav class="bg-white shadow-md sticky top-0 z-40">
    <div class="max-w-7xl mx-auto px-4">
        <!-- 上层导航 - Logo和用户功能区 -->
        <div class="flex justify-between items-center h-16">
            <div class="flex items-center">
                <button onclick="window.location.href='/'" class="p-2 rounded-md hover:bg-gray-100">
                    <i data-lucide="arrow-left"></i>
                </button>
                <span class="ml-4 text-xl font-bold">体育比分网</span>
            </div>
            <div class="flex items-center space-x-4">
                <i data-lucide="search"></i>
                <i data-lucide="bell"></i>
                <i data-lucide="user"></i>
            </div>
        </div>

        <!-- 下层导航 - 主要功能区 -->
        <div class="flex items-center space-x-6 h-12 text-gray-600">
            <a href="/"
               class="flex items-center h-full border-b-2 border-transparent hover:text-blue-500 hover:border-blue-500 px-1">
                比分直播
            </a>
            <a href="/video/video.html"
               class="flex items-center h-full border-b-2 border-blue-500 text-blue-500 px-1">
                <i data-lucide="play" class="w-4 h-4 mr-1"></i>
                视频集锦
            </a>
            <a href="/news/news.html"
               class="flex items-center h-full border-b-2 border-transparent hover:text-blue-500 hover:border-blue-500 px-1">
                <i data-lucide="newspaper" class="w-4 h-4 mr-1"></i>
                新闻资讯
            </a>
        </div>
    </div>
</nav>

<main class="max-w-7xl mx-auto px-4 py-6">
    <!-- 加载状态 -->
    <div id="loading" class="flex justify-center py-8">
        <div class="loading-spinner"></div>
    </div>

    <!-- 视频容器 -->
    <div id="videoContainer" class="grid grid-cols-1 gap-6">
        <!-- ScoreBat 视频将在这里显示 -->
    </div>

    <!-- 错误提示 -->
    <div id="error" class="hidden text-center py-8 text-red-500">
        加载失败，请稍后重试
    </div>
</main>

<script>
    // 初始化图标
    lucide.createIcons();

    // 获取并显示视频
    async function fetchVideos() {
        const loading = document.getElementById('loading');
        const error = document.getElementById('error');
        const container = document.getElementById('videoContainer');

        try {
            loading.style.display = 'flex';
            error.style.display = 'none';
            container.style.display = 'none';

            // 使用 ScoreBat API 获取视频
            const response = await fetch('https://www.scorebat.com/video-api/v3/feed/?token=MTgzODI3XzE3MzAxODc2ODlfNjZmZmY0OGFiMzVhYWZiMDc0ZTM1ZjVjZDZkM2E1ZjE1MjgwYWU0Nw==');
            const data = await response.json();

            if (data && data.response) {
                // 清空容器
                container.innerHTML = '';

                // 添加视频
                data.response.forEach(video => {
                    const videoElement = document.createElement('div');
                    videoElement.className = 'bg-white rounded-lg shadow overflow-hidden';
                    videoElement.innerHTML = `
                            <div class="p-4">
                                <h3 class="font-medium mb-2">${video.title}</h3>
                                <div class="text-sm text-gray-500 mb-4">
                                    ${new Date(video.date).toLocaleDateString()}
                                </div>
                                <div class="scorebat-video-container">
                                    ${video.videos[0].embed}
                                </div>
                            </div>
                        `;
                    container.appendChild(videoElement);
                });

                loading.style.display = 'none';
                container.style.display = 'grid';
            } else {
                throw new Error('Failed to load videos');
            }
        } catch (err) {
            console.error('Error loading videos:', err);
            loading.style.display = 'none';
            error.style.display = 'block';
        }
    }

    // 页面加载完成后获取视频
    document.addEventListener('DOMContentLoaded', () => {
        fetchVideos();

        // 每5分钟刷新一次
        setInterval(() => {
            if (!document.hidden) {
                fetchVideos();
            }
        }, 300000);
    });

    // 监听页面可见性变化
    document.addEventListener('visibilitychange', () => {
        if (!document.hidden) {
            fetchVideos();
        }
    });
</script>
</body>
</html>
